using System;
using org.pdfbox.pdmodel;
using org.pdfbox.util;

namespace umbSearch.businessLogic
{
	/// <summary>
	/// Summary description for IndexPdf.
	/// </summary>
    public class IndexPdf : interfaces.IUmbracoSearchFileFilter
	{
		public IndexPdf()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		#region IUmbracoSearchFileFilter Members

		public string[] extensions
		{
			get
			{
				string[] _extensions = {"pdf"};
				return _extensions;
			}
		}

		public string returnText(string FullPathToFile)
		{
		    PDDocument doc;
		    string result = "";
			try 
			{
				doc = PDDocument.load(FullPathToFile);
				PDFTextStripper stripper = new PDFTextStripper();
			    result = stripper.getText(doc);
                doc.close();
			    return result;
			} 
			catch (Exception ePdf) 
			{
				return "Error indexing pdf '" + FullPathToFile + "': " + ePdf.ToString();
			}
		}

		#endregion
	}
}
